{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.int64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "a = torch.tensor(1.2)\n",
    "a = torch.tensor([[1.2,1.3],[2.0,2.1]])\n",
    "a = torch.zeros(3,4,dtype=torch.float16)\n",
    "a = torch.randn(3,4).long()\n",
    "a.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.float32 torch.Size([2, 3]) cpu\n",
      "cuda:0 cpu\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "a = torch.randn(2,3)\n",
    "print(a.dtype,a.shape,a.device)\n",
    "# a = a.cuda()\n",
    "a = a.cuda(0)\n",
    "a = a.to(\"cuda:0\")\n",
    "c = a.cpu()\n",
    "c = a.to(\"cpu\")\n",
    "print(a.device,c.device)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "\n",
    "a = torch.randn(2,3)\n",
    "b = torch.randn(3,2).cuda()\n",
    "\n",
    "# a@b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "float32\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "a = torch.randn(2,3)\n",
    "print(a.numpy().dtype)\n",
    "type(a.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tensor([[-0.0751, -0.9224, -1.3026,  1.3996],\n",
       "         [ 0.3935, -0.0633,  0.8976, -0.3859],\n",
       "         [-0.4254, -0.1437, -0.2673, -0.5755]], dtype=torch.float64),\n",
       " torch.float64)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "import numpy as np\n",
    "\n",
    "a = np.random.randn(3,4)\n",
    "\n",
    "b = torch.tensor(a)\n",
    "b,b.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([1.0842, 1.0723])\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "tensor([[1.0842],\n",
       "        [1.0723]])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "a = torch.randn(2,3)\n",
    "\n",
    "print(a.max(dim=1)[0])\n",
    "# a.max(dim=1)[1]\n",
    "\n",
    "index = a.argmax(dim=1,keepdim=True)\n",
    "c = torch.gather(a,1,index)\n",
    "c\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py310",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
